import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-07-04
 * Time: 14:29
 */
public class Test21 {
    public static boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length, n = matrix[0].length;
        // 特殊判断
        if(matrix == null || m == 0 || n == 0) {
            return false;
        }
        int i = 0,j = n-1;
        while(i < m && j >=0) {
            if(matrix[i][j] == target) {
                return true;
            }else if(matrix[i][j] > target) {
                j--;
            }else {
                i++;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        int[][] num = new int[m][n];

        for(int i = 0; i < m; i++) {
            for(int j = 0; j < n; j++) {
                num[i][j] = sc.nextInt();
            }
        }
        int target = sc.nextInt();
        boolean ret = searchMatrix(num,target);
        System.out.println(ret);
    }
}
